<?php
require_once '../config/config.php';
require_once 'inc/session.php';

$menu = -1;

if (!isset($_GET['cmd'])) {
    header('Location:tableau_bord.php');
    exit();
}

$id_commande = $_GET['cmd'];
$sql = 'SELECT id, id_etablissement, id_edition, id_abonnement, nb_beneficiares, date_creation, etat, commentaire FROM commande WHERE offre_essai = 0';
$req = mysql_query($sql) or die(mysql_error());
$res = mysql_fetch_array($req);

$date_creation = date('d-m-Y H:i', strtotime($res['date_creation']));

//# etablissement
$id_etablisssment = $res['id_etablissement'];
$sql_etablissement = "SELECT etablissement, ville, adresse, code_postal, connaissance FROM etablissement WHERE id = " . $id_etablisssment;
$req_etablissement = mysql_query($sql_etablissement);
$res_etablissement = mysql_fetch_array($req_etablissement);

$etablissement = $res_etablissement['etablissement'];
$ville = $res_etablissement['ville'];
$adresse = $res_etablissement['adresse'];
$code_postal = $res_etablissement['code_postal'];

$commentaire = $res['commentaire'];

//# connaissance
switch ($res_etablissement['connaissance']) {
    case 1:
        $connaissance = "Par un moteur de recherche";
        break;
    case 2:
        $connaissance = "Par un abonné";
        break;
    case 3:
        $connaissance = "Par les réseaux sociaux";
        break;
    case 4:
        $connaissance = "Par la presse";
        break;
    case 5:
        $connaissance = "Par un emailing";
        break;
    case 6:
        $connaissance = "Par un contact avec l’équipe de l’Essentiel du sup";
        break;
    case 7:
        $connaissance = "Autre";
        break;
    default :
        $connaissance = "-";
        break;
}

//# contact administrative
$sql_contact = "SELECT nom, prenom, fonction, telephone, email FROM contact_administratif WHERE id_etablissement = " . $id_etablisssment;
$req_contact = mysql_query($sql_contact);
$res_contact = mysql_fetch_array($req_contact);

$nom_contact = ucwords($res_contact['nom']);
$prenom_contact = ucwords($res_contact['prenom']);
$fonction_contact = $res_contact['fonction'];
$tel_contact = $res_contact['telephone'];
$email_contact = $res_contact['email'];

//# edition
switch ($res['id_edition']) {
    case 1:
        $edition = "Ecoles de management";
        break;
    case 2:
        $edition = "Ecoles d’ingénieurs";
        break;
    case 3:
        $edition = "Universités";
        break;
}

//# nb beneficiares
$sql_beneficiare = "SELECT id FROM beneficiare WHERE id_commande = " . $id_commande;
$req_beneficiare = mysql_query($sql_beneficiare);
$nb_beneficiares = mysql_num_rows($req_beneficiare);

//# statut
switch ($res['etat']) {
    case 0:
        $statut = "En cours";
        break;
    case 1:
        $statut = "Activé";
        break;
    case 2:
        $statut = "Désactivé";
        break;
    default:
        break;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Interface Administration | L'essentiel du sup</title>
        <link rel="shortcut icon" href="images/favicon.ico" />
        <link rel="stylesheet" href="css/style.css" type="text/css" />
        <!--[if IE 9]>
            <link rel="stylesheet" media="screen" href="css/ie9.css"/>
        <![endif]-->
        <!--[if IE 8]>
            <link rel="stylesheet" media="screen" href="css/ie8.css"/>
        <![endif]-->
        <!--[if IE 7]>
            <link rel="stylesheet" media="screen" href="css/ie7.css"/>
        <![endif]-->
        <script type="text/javascript" src="js/plugins/jquery-1.7.min.js"></script>
        <script type="text/javascript" src="js/plugins/jquery.flot.min.js"></script>
        <script type="text/javascript" src="js/plugins/jquery.flot.resize.min.js"></script>
        <script type="text/javascript" src="js/plugins/jquery-ui-1.8.16.custom.min.js"></script>
        <script type="text/javascript" src="js/custom/general.js"></script>
        <script type="text/javascript">
            jQuery(document).ready(function() {
                jQuery("#btn_retour").click(function(e) {
                    e.preventDefault();
                    var url = 'gestion_abonnes.php';
                    window.location.href = url;
                });
            });
        </script>
        <!--[if lt IE 9]>
                <script src="js/css3-mediaqueries.js"></script>
        <![endif]-->
    </head>
    <body class="loggedin">
        <?php include('inc/header.php') ?>
        <div class="mainwrapper">
            <div class="mainwrapperinner">
                <?php include('inc/menu.php') ?>
                <div class="maincontent noright">
                    <div class="maincontentinner">
                        <ul class="maintabmenu">
                            <li class="current">
                                <a>Abonnement</a>
                            </li>
                        </ul>
                        <div class="content">
                            <div class="contenttitle">
                                <h2 class="widgets">
                                    <span>Details abonnement</span>
                                </h2>
                            </div>
                            <br/>
                            <form id="validate" class="stdform stdform2" action="" method="post" enctype="multipart/form-data">
                                <p>
                                    <label>N° :</label> 
                                    <span class="field"><?php echo $id_commande ?></span>
                                </p>
                                <p>
                                    <label>Date de création :</label> 
                                    <span class="field"><?php echo $date_creation ?></span>
                                </p>
                                <p>
                                    <label>Etablissement :</label> 
                                    <span class="field"><?php echo $etablissement ?></span>
                                </p>
                                <p>
                                    <label>Ville :</label> 
                                    <span class="field"><?php echo $ville ?></span>
                                </p>
                                <p>
                                    <label>Adresse :</label> 
                                    <span class="field"><?php echo $adresse ?></span>
                                </p>
                                <p>
                                    <label>Code postal :</label> 
                                    <span class="field"><?php echo $code_postal ?></span>
                                </p>
                                <p>
                                    <label>Edition :</label> 
                                    <span class="field"><?php echo $edition ?></span>
                                </p>
                                <p>
                                    <label>Nombre de bénéficiaires :</label> 
                                    <span class="field"><?php echo $nb_beneficiares ?></span>
                                </p>
                                <p>
                                    <label>Statut :</label> 
                                    <span class="field"><?php echo $statut ?></span>
                                </p>
                                <p>
                                    <label>Connu :</label> 
                                    <span class="field"><?php echo $connaissance ?></span>
                                </p>
                            </form>
                            <br clear="all" />
                            <div class="contenttitle">
                                <h2 class="widgets">
                                    <span>Contact administratif</span>
                                </h2>
                            </div>
                            <br/>
                            <form id="validate" class="stdform stdform2" action="" method="post" enctype="multipart/form-data">
                                <p>
                                    <label>Nom :</label> 
                                    <span class="field"><?php echo $nom_contact ?></span>
                                </p>
                                <p>
                                    <label>Prénom :</label> 
                                    <span class="field"><?php echo $prenom_contact ?></span>
                                </p>
                                <p>
                                    <label>Fonction :</label> 
                                    <span class="field"><?php echo $fonction_contact ?></span>
                                </p>
                                <p>
                                    <label>Téléphone :</label> 
                                    <span class="field"><?php echo $tel_contact ?></span>
                                </p>
                                <p>
                                    <label>E-mail :</label> 
                                    <span class="field"><?php echo $email_contact ?></span>
                                </p>
                                <p class="stdformbutton">
                                    <input id="btn_retour" type="reset" class="reset radius2" value="Retour" />
                                </p>
                            </form>
                            <br clear="all" />
                            <div class="contenttitle">
                                <h2 class="form">
                                    <span>Commentaire Administrateur</span>
                                </h2>
                            </div>
                            <br/>
                            <form id="validate" class="stdform stdform2" action="" method="post" enctype="multipart/form-data">
                                <p>
                                    <label>Commentaire :</label> 
                                    <span class="field" style="min-height: 20px;"><?php echo $commentaire ?></span>
                                </p>
                            </form>
                            <br clear="all" />
                        </div>
                    </div>
                    <div class="footer">
                        <p></p>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
